﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Wicresoft.JDPostBoard.Entity;
using Wicresoft.Framework.Organization;
using System.Text;
using Wicresoft.Busi.BizLogic;

public partial class NewMeetingRoom_RoomApplyView : BaseAuthenticationPage
{
    #region Property ApplyID
    public int ApplyID
    {
        get
        {
            if (Request["ApplyID"] != null)
                return int.Parse(Request["ApplyID"]);
            else
                return int.MinValue;
        }
    }
    #endregion

    #region Property UserType
    public string UserType
    {
        get
        {
            return Request["UserType"];
        }
    }
    #endregion


    #region Property ApplyStatus
    public string ApplyStatus
    {
        get
        {
            if (ViewState["ApplyStatus"] != null)
                return ViewState["ApplyStatus"].ToString();
            else
                return "";
        }
        set
        {
            ViewState["ApplyStatus"] = value;
        }
    }
    #endregion
    #region 绑定时间 BindWorkTime
    /// <summary>
    /// 绑定时间
    /// </summary>
    /// <param name="ddl">时间选择下拉框</param>
    /// <param name="start">起始时间</param>
    /// <param name="end">终止时间</param>
    /// <param name="interval">时间间隔</param>
    protected void BindWorkTime(DropDownList ddl, int start, int end, int interval)
    {
        int period = 60 / interval;
        int len = end - start + 1;
        ListItem[] items = new ListItem[len * period];

        for (int i = 0; i < len; i++)
        {
            for (int j = 0; j < period; j++)
                items[i * period + j] = new ListItem(string.Format("{00:00}", (i + start)) + ":" + string.Format("{00:00}", (j * interval)));
        }
        ddl.Items.AddRange(items);
    }
    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        this.UseTabber = true;
        this.Title = "详细信息";

        if (!IsPostBack)
        {
            BindWorkTime(ddlStartTime, 6, 22, 15);
            BindWorkTime(ddlEndTime, 6, 22, 15);

            loadRoom();
            initMeetingType();
            LoadGoodsInfo();
            LoadApplyInfo();

            if (UserType == "view")
            {
                fg0.Visible = false;
                this.tdPass.Visible = false;

                fg1.Visible = false;
                this.tdReject.Visible = false;

                this.tdCancel.Visible = false;

                this.tdClose.Visible = false;
            }
            if (UserType == "Cancel")
            {
                fg0.Visible = false;
                this.tdPass.Visible = false;

                fg1.Visible = false;
                this.tdReject.Visible = false;

                fg2.Visible = false;
                this.tdCancel2.Visible = false;

                this.txtShyj.Visible = false;
            }
            if (UserType == "Static")
            {
                this.tdCancel.Visible = false;

                fg0.Visible = false;
                this.tdPass.Visible = false;

                fg1.Visible = false;
                this.tdReject.Visible = false;

                fg2.Visible = false;
                this.tdCancel2.Visible = false;

            }
            if (UserType == "Approve")
            {
                this.tdCancel.Visible = false;
                this.fg0.Visible = false;

                this.ddlRoom.Enabled = true;
            }
        }
    }

    #region 根据用户初始化会议室下拉框
    private void loadRoom()
    {
        string[] strRoomStatus = new string[] { Wicresoft.Busi.Entity.RoomStatus.OPENED };
        DataTable dt = BLMeetingRooms.GetMeetingRooms(strRoomStatus, CurrentUser.ID);
        dt.Columns.Add("RoomDesc", typeof(System.String));
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            DataRow dr = dt.Rows[i];
            dr["RoomDesc"] = dr[Wicresoft.Busi.Entity.vwMeetingRooms.SQLCOL_ROOMNAME].ToString() + " （座位数：" + dr[Wicresoft.Busi.Entity.vwMeetingRooms.SQLCOL_SEATSCOUNT].ToString() + "人）";
        }
        this.ddlRoom.DataSource = dt;
        this.ddlRoom.DataTextField = "RoomDesc";
        this.ddlRoom.DataValueField = Wicresoft.Busi.Entity.vwMeetingRooms.SQLCOL_ID;
        this.ddlRoom.DataBind();
        if (UserType == "Approve" || UserType == "Static")
        {
            this.ddlRoom.Items.Insert(0, new ListItem("--请选择--", "-1"));
        }
        else if (UserType == "view")
        {
            this.ddlRoom.Items.Insert(0, new ListItem("--尚未选择--", "-1"));
        }
        else
        {
            this.ddlRoom.Items.Insert(0, new ListItem("--尚未选择--", "-1"));
        }
    }
    #endregion

    #region 初始化会议室类型
    private void initMeetingType()
    {
        DataTable dt = Wicresoft.Busi.BizLogic.BLDic_MeetingRoom.GetMeetingType();
        this.ddlType.DataSource = dt;
        this.ddlType.DataTextField = Wicresoft.Busi.Entity.Dic_MeetingRoom.SQLCOL_PROPERTYNAME;
        this.ddlType.DataValueField = Wicresoft.Busi.Entity.Dic_MeetingRoom.SQLCOL_PROPERTYID;
        this.ddlType.DataBind();
    }
    #endregion

    #region 会场要求
    private void LoadGoodsInfo()
    {
        DataTable dt = new DataTable();
        if (this.ApplyID == int.MinValue)
        {
            dt = Wicresoft.Busi.BizLogic.BLMeetingRoomGoods.GetMeetingGoodsList();
            this.cblGoods.DataSource = dt;
            this.cblGoods.DataTextField = "GoodsName";
            this.cblGoods.DataValueField = "ID";
            this.cblGoods.DataBind();
        }
        else
        {
            dt = Wicresoft.Busi.BizLogic.BLMeetingRoomGoods.GetMeetingApplyGoods(this.ApplyID);
            this.cblGoods.DataSource = dt;
            this.cblGoods.DataTextField = "GoodsName";
            this.cblGoods.DataValueField = "GoodsID";
            this.cblGoods.DataBind();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["IsNeed"] != DBNull.Value && Convert.ToBoolean(dt.Rows[i]["IsNeed"]) != false)
                    cblGoods.Items[i].Selected = true;
            }
        }
    }
    #endregion

    #region 根据申请ID,读取申请详细信息
    private void LoadApplyInfo()
    {
        MeetingRoomApply info = new MeetingRoomApply(this.ApplyID);
        info.Load();
        if (info != null)
        {
            MeetingRooms room = new MeetingRooms(info.RoomID);
            room.Load();
            //ltRoomName.Text = room.RoomName;
            if (room.ID != int.MinValue)
            {
                if (UserType != "Approve")
                    this.ddlRoom.SelectedValue = room.ID.ToString();
            }

            ltHyrs.Text = info.PeopleCount.ToString();
            ltSbbm.Text = info.Sbbm;
            ltRemark4.Text = info.Remark4;
            ltTopic.Text = info.Topic;
            txtDate.Text = info.MeetingDate.ToString("yyyy-MM-dd ");
            ltHyhb.Text = info.Hb;
            ltHyc.Text = info.Hyc;
            ltZsp.Text = info.Zsp;
            ltXk.Text = info.Xk;
            ltRemark1.Text = info.Remark1;
            ltAttendee.Text = info.Remark3;
            ltRemark3.Text = info.Phone;

            if (info.Remark2 == 1)
                cbImportance.Checked = true;
            else
                cbImportance.Checked = false;
            this.cbImportance.Enabled = false;

            this.ddlType.SelectedValue = info.Type.ToString();
            this.ddlType.Enabled = false;

            foreach (ListItem li in cblGoods.Items)
            {
                MeetingRoomApplyGoods oGoods = new MeetingRoomApplyGoods();
                oGoods.ApplyID = this.ApplyID;
                oGoods.GoodsID = int.Parse(li.Value);
                oGoods.Load("ApplyID='" + this.ApplyID + "' and GoodsID='" + oGoods.GoodsID + "'");
                li.Selected = oGoods.IsNeed;
            }
            cblGoods.Enabled = true;
            txtNote.Text = info.Notes;
            ltNote.Text = info.Notes;
            ltShyj.Text = info.Shyj;
            txtShyj.Text = info.Shyj;


            txtPeopCount.Text = info.PeopleCount.ToString();


            tbPhone.Text = info.Phone;
            txtTopic.Text = info.Topic;
            ListItem lis = ddlStartTime.Items.FindByValue(info.StartTime);
            if (lis != null)
                ddlStartTime.SelectedValue = lis.Value;
            lis = ddlEndTime.Items.FindByValue(info.EndTime);
            if (lis != null)
                ddlEndTime.SelectedValue = info.EndTime;


            txtHyhb.Text = info.Hb;
            txtHyc.Text = info.Hyc;
            txtZsp.Text = info.Zsp;
            txtXk.Text = info.Xk;
            txtRemark1.Text = info.Remark1;
            txtRemark3.Text = info.Remark3;

            if (info.Status == Wicresoft.Busi.Entity.MeetingStatus.POST)
            {
                ltShyj.Visible = false;
                txtShyj.Visible = true;
                fg0.Visible = true;
                this.tdPass.Visible = true;

                fg1.Visible = true;
                this.tdReject.Visible = true;
                this.ddlRoom.Enabled = true;

            }
            else if (info.Status == Wicresoft.Busi.Entity.MeetingStatus.AUDIT)
            {
                tdCancel.Visible = true;

                fg0.Visible = false;
                this.tdPass.Visible = false;

                fg1.Visible = false;
                this.tdReject.Visible = false;

                fg2.Visible = false;
                this.tdCancel2.Visible = false;

                if (string.IsNullOrEmpty(UserType))
                {
                    fg4.Visible = true;
                    this.tdModify.Visible = true;

                    fg5.Visible = true;
                    this.tdMessage.Visible = true;

                    this.ddlRoom.Enabled = true;

                    this.txtPeopCount.Visible = true;

                    this.ltHyrs.Visible = false;
                    this.tbPhone.Visible = true;
                    this.txtTopic.Visible = true;

                    this.txtHyhb.Visible = true;
                    this.txtHyc.Visible = true;
                    this.txtXk.Visible = true;
                    this.txtZsp.Visible = true;
                    this.txtRemark1.Visible = true;
                    this.txtRemark3.Visible = true;
                    this.ltRemark1.Visible = false;
                    this.ltAttendee.Visible = false;
                    this.ltHyhb.Visible = false;
                    this.ltHyc.Visible = false;
                    this.ltRemark3.Visible = false;
                    this.ltTopic.Visible = false;
                    this.ltXk.Visible = false;
                    this.ltNote.Visible = false;
                }
            }
            else
            {
                fg0.Visible = false;
                this.tdPass.Visible = false;

                fg1.Visible = false;
                this.tdReject.Visible = false;

                fg2.Visible = false;
                this.tdCancel.Visible = false;
            }
            ApplyStatus = info.Status;
        }
    }
    #endregion


    protected void btnCancel_Click(object sender, System.EventArgs e)
    {

        MeetingRoomApply info = new MeetingRoomApply(this.ApplyID);
        info.Load();
        info.Status = Wicresoft.Busi.Entity.MeetingStatus.CANCEL;
        info.UpdateByPrimaryKey();

        #region 发送申请取消提醒

        User[] Users = OrganizationHelper.GetUserInfoListByRole(Wicresoft.Busi.Entity.MeetingRoles.Manage);
        foreach (User user in Users)
        {
            try
            {
                MsgUtil msgUtil = new MsgUtil(user.ID.ToString(), user.Name, user.DisplayName, string.Empty);
                StringBuilder sbTag = new StringBuilder();
                sbTag.Append(info.Topic);
                sbTag.Append(";" + info.MeetingDate.ToString("yyyy-MM-dd") + " " + info.StartTime + "-" + info.EndTime);
                sbTag.Append(";" + (new MeetingRooms(info.RoomID)).RoomName);
                sbTag.Append(";" + info.Notes);
                msgUtil.SendMessage(CurrentUser.Name, string.Empty, "会议室申请取消：" + info.Topic, sbTag.ToString());
            }
            catch { }
        }

        #endregion
        ClientScript.RegisterStartupScript(this.GetType(), "RefreshParent", "<script>alert('取消申请成功');parent.document.getElementById('ctl00$ListToolBarPlaceHolder$btnRefresh').click();</script>");
        //WebCommon.ShowMessage(this.Page, "操作成功.");
    }

    protected void btnCancel2_Click(object sender, System.EventArgs e)
    {
        MeetingRoomApply info = new MeetingRoomApply(ApplyID);
        info.Load();
        info.Status = Wicresoft.Busi.Entity.MeetingStatus.BOOKEDCANCEL;
        info.AuditUserID = CurrentUser.Name;
        info.AuditUserName = CurrentUser.DisplayName;
        info.AuditTime = DateTime.Now;
        info.UpdateByPrimaryKey();

        #region 发送申请取消提醒

        User[] Users = OrganizationHelper.GetUserInfoListByRole(Wicresoft.Busi.Entity.MeetingRoles.Manage);
        foreach (User user in Users)
        {
            try
            {
                MsgUtil msgUtil = new MsgUtil(user.ID.ToString(), user.Name, user.DisplayName, string.Empty);
                StringBuilder sbTag = new StringBuilder();
                sbTag.Append(info.Topic);
                sbTag.Append(";" + info.MeetingDate.ToString("yyyy-MM-dd") + " " + info.StartTime + "-" + info.EndTime);
                sbTag.Append(";" + (new MeetingRooms(info.RoomID)).RoomName);
                sbTag.Append(";" + info.Notes);
                msgUtil.SendMessage(CurrentUser.Name, string.Empty, "会议室取消占用：" + info.Topic, sbTag.ToString());
            }
            catch { }
        }

        #endregion

        ClientScript.RegisterStartupScript(this.GetType(), "RefreshParent", "<script>alert('取消占用成功');parent.document.getElementById('ctl00$ListToolBarPlaceHolder$btnRefresh').click();</script>");

        //WebCommon.ShowMessage(this.Page, "操作成功.");
    }

    protected void btnPass_Click(object sender, System.EventArgs e)
    {

        MeetingRoomApply info = new MeetingRoomApply(ApplyID);
        info.Load();
        if (!CanUseRoom(info))
            return;
        info.Status = Wicresoft.Busi.Entity.MeetingStatus.AUDIT;
        info.AuditUserID = CurrentUser.Name;
        info.AuditUserName = CurrentUser.DisplayName;
        info.AuditTime = DateTime.Now;
        info.Shyj = this.txtShyj.Text.Trim();
        info.RoomID = int.Parse(this.ddlRoom.SelectedValue);
       
        info.UpdateByIdentity();

        MeetingRooms met = new MeetingRooms(info.RoomID);
        met.Load();


        #region 发送审核通过提醒

        User user = OrganizationHelper.GetUserInfo(info.Applicant);
        string mobile = string.Empty;
        if (user != null)
        {
            DataTable dtData = Wicresoft.Common.DataAccess.ExecuteSql("Wicresoft.Framework.ConnectionString",
             string.Format(@"Select ValueString from PropertyData where NodeID='{0}' and PropertyID in (
                    select ID from Property where Name='Mobile')", user.ID.ToString())).Tables[0];
            mobile = dtData.Rows.Count == 0 ? "" : dtData.Rows[0]["ValueString"].ToString();
        }
        if (mobile != string.Empty)
        {
            try
            {
                MsgUtil msgUtil = new MsgUtil(user.ID.ToString(), user.Name, user.DisplayName, mobile);
                StringBuilder sbTag = new StringBuilder();
                sbTag.Append(info.Topic);
                sbTag.Append(";" + info.MeetingDate.ToString("yyyy-MM-dd") + " " + info.StartTime + "-" + info.EndTime);
                sbTag.Append(";" + (new MeetingRooms(info.RoomID)).RoomName);
                sbTag.Append(";" + info.Notes);
                Response.Write("会议室申请审核通过：" + info.Topic + "安排在" + met.RoomName + "。");
                msgUtil.SendMessage(CurrentUser.Name, string.Empty, "会议室申请审核通过：" + info.Topic + "被安排在" + met.RoomName + "。", sbTag.ToString());
            }
            catch { }
        }
        #endregion
        ClientScript.RegisterStartupScript(this.GetType(), "RefreshParent", "<script>alert('申请已审核通过');parent.document.getElementById('ctl00$ListToolBarPlaceHolder$btnRefresh').click();</script>");

        //WebCommon.ShowMessage(this.Page, "申请已审核通过.");
    }

    protected void btnReject_Click(object sender, System.EventArgs e)
    {
        if (this.txtShyj.Text.Trim() == "")
        {
            WebCommon.ShowMessage(this, "请输入审核意见");
            this.txtShyj.Focus();
            return;
        }
        MeetingRoomApply info = new MeetingRoomApply(ApplyID);
        info.Load();
        info.Status = Wicresoft.Busi.Entity.MeetingStatus.FAIL;
        info.AuditUserID = CurrentUser.Name;
        info.AuditUserName = CurrentUser.DisplayName;
        info.AuditTime = DateTime.Now;
        info.Shyj = this.txtShyj.Text.Trim();
        info.UpdateByPrimaryKey();

        #region 发送不通过提醒

        User user = OrganizationHelper.GetUserInfo(info.Applicant);
        string mobile = string.Empty;
        if (user != null)
        {
            DataTable dtData = Wicresoft.Common.DataAccess.ExecuteSql("Wicresoft.Framework.ConnectionString",
             string.Format(@"Select ValueString from PropertyData where NodeID='{0}' and PropertyID in (
                    select ID from Property where Name='Mobile')", user.ID.ToString())).Tables[0];
            mobile = dtData.Rows.Count == 0 ? "" : dtData.Rows[0]["ValueString"].ToString();
        }
        if (mobile != string.Empty)
        {
            try
            {
                MsgUtil msgUtil = new MsgUtil(user.ID.ToString(), user.Name, user.DisplayName, mobile);
                StringBuilder sbTag = new StringBuilder();
                sbTag.Append(info.Topic);
                sbTag.Append(";" + info.MeetingDate.ToString("yyyy-MM-dd") + " " + info.StartTime + "-" + info.EndTime);
                sbTag.Append(";" + (new MeetingRooms(info.RoomID)).RoomName);
                sbTag.Append(";" + info.Notes);
                msgUtil.SendMessage(CurrentUser.Name, string.Empty, "会议室申请被驳回：" + info.Topic, sbTag.ToString());
            }
            catch
            { }
        }
        ClientScript.RegisterStartupScript(this.GetType(), "RefreshParent", "<script>alert('申请已退回');parent.document.getElementById('ctl00$ListToolBarPlaceHolder$btnRefresh').click();</script>");

        //WebCommon.ShowMessage(this.Page, "申请已退回.");
        #endregion
    }



    private void AddMeetingApplyGoods(int AppID)
    {
        foreach (ListItem li in cblGoods.Items)
        {
            MeetingRoomApplyGoods oGoods = new MeetingRoomApplyGoods();
            oGoods.ApplyID = AppID;
            oGoods.GoodsID = int.Parse(li.Value);
            oGoods.IsNeed = li.Selected;
            oGoods.GoodsCount = 0;
            oGoods.Add();
        }
    }
    private void UpdateMeetingApplyGoods()
    {
        foreach (ListItem li in cblGoods.Items)
        {
            MeetingRoomApplyGoods oGoods = new MeetingRoomApplyGoods(this.ApplyID, int.Parse(li.Value));
            oGoods.Load();
            oGoods.IsNeed = li.Selected;
            oGoods.Update();
        }
    }




    protected void btnModify_Click(object sender, EventArgs e)
    {
        MeetingRoomApply info = new MeetingRoomApply(ApplyID);
        info.Load();
        if (!CanUseRoom(info))
            return;

        info.RoomID = int.Parse(this.ddlRoom.SelectedValue);
        info.Notes = this.txtNote.Text.Trim();
        info.StartTime = this.ddlStartTime.SelectedValue;
        info.EndTime = this.ddlEndTime.SelectedValue;
        info.ConvertTime = ConvertToCover(this.ddlStartTime.SelectedValue, this.ddlEndTime.SelectedValue);
        info.Hb = this.txtHyhb.Text;
        info.Hyc = this.txtHyc.Text;
        info.Xk = this.txtXk.Text;
        info.Zsp = this.txtZsp.Text;
        info.Remark1 = this.txtRemark1.Text;
        info.Remark3 = this.txtRemark3.Text;

        int nPeopCount = 0;

        try
        {
            nPeopCount = int.Parse(this.txtPeopCount.Text);
        }
        catch
        {
            WebCommon.ShowMessage(this.Page, "参加人数必须是整数.");
            return;
        }

        info.PeopleCount = nPeopCount;
        info.Phone = this.tbPhone.Text;
        info.Topic = this.txtTopic.Text;

        info.UpdateByIdentity();
        UpdateMeetingApplyGoods();
        ClientScript.RegisterStartupScript(this.Page.GetType(), "result", "<script language=JavaScript>alert('已保存修改,请发送短信通知相关人员!');window.close();parent.document.getElementById('ctl00$ListToolBarPlaceHolder$btnRefresh').click();</script>");

    }

    protected bool CanUseRoom(MeetingRoomApply apply)
    {
        if (this.ddlRoom.SelectedValue == "-1")
        {
            WebCommon.ShowMessage(this, "请选择会议室");
            this.ddlRoom.Focus();
            return false;
        }

        bool bExit = false;
        int nApplyID = 0;
        int RoomID = int.Parse(this.ddlRoom.SelectedValue);
        Wicresoft.Busi.Entity.MeetingRooms room = new Wicresoft.Busi.Entity.MeetingRooms(RoomID);
        room.Load();
        // int nPeopCount = int.Parse(ltHyrs.Text);
        //if (nPeopCount > room.SeatsCount)
        //{
        //    WebCommon.ShowMessage(this.Page, "参加人数超过了" + Util.SceneName + "可容纳人数.");
        //    return false;
        //}

        if (this.txtShyj.Text.Trim() == "")
        {
            WebCommon.ShowMessage(this, "请输入审核意见");
            this.txtShyj.Focus();
            return false;
        }

        string[] strMeetingStatus = new string[] { Wicresoft.Busi.Entity.MeetingStatus.POST, Wicresoft.Busi.Entity.MeetingStatus.AUDIT };

        Wicresoft.Common.PagingEntity pe = new Wicresoft.Common.PagingEntity();
        pe.PageIndex = 0;
        pe.PageSize = 10;
        pe.TableName = "vwMeetingRoomApply2";
        pe.SelectString = "*";
        pe.DescString = "ApplyDate DESC";
        pe.AscString = "ApplyDate DESC";
        DataTable dtTemp = BLMeetingRoomApply.GetMeetingRoomApplyByRoomID(RoomID, apply.MeetingDate.ToString("yyyy-MM-dd"), strMeetingStatus, CurrentUser.ID, pe);

        int ConverTime = ConvertToCover(apply.StartTime, apply.EndTime);
        for (int i = 0; i < dtTemp.Rows.Count; i++)
        {
            if (DateTime.Parse(dtTemp.Rows[i]["MeetingDate"].ToString()).ToString("yyyy-MM-dd").Equals(apply.MeetingDate.ToString("yyyy-MM-dd")) && int.Parse(dtTemp.Rows[i]["ID"].ToString()) != this.ApplyID)
            {
                switch (ConverTime.ToString())
                {
                    case "0":
                        if (!dtTemp.Rows[i]["ConvertTime"].ToString().Equals("1"))
                        {
                            bExit = true;
                            nApplyID = int.Parse(dtTemp.Rows[i]["ID"].ToString());
                        }
                        break;
                    case "1":
                        if (!dtTemp.Rows[i]["ConvertTime"].ToString().Equals("0"))
                        {
                            bExit = true;
                            nApplyID = int.Parse(dtTemp.Rows[i]["ID"].ToString());
                        }
                        break;
                    case "3":
                        bExit = true;
                        nApplyID = int.Parse(dtTemp.Rows[i]["ID"].ToString());
                        break;
                }
            }
            if (bExit) break;
        }

        if (!BLMeetingRoomApply.IsRoomNotApplied(ApplyID, int.Parse(this.ddlRoom.SelectedValue), apply.MeetingDate.ToString("yyyy-MM-dd"), apply.StartTime, apply.EndTime))
        {
            Wicresoft.Busi.BizLogic.WebCommon.ShowForm(this.Page, "ShowMessage.aspx?MsgType=1&ApplyID=" + nApplyID, 400, 380, true, null);
            return false;
        }

        return true;
    }

    #region 转换时间 ConvertToCover
    private int ConvertToCover(string StartTime, string EndTime)
    {
        int CoverTime = 0;
        if (DateTime.Parse(EndTime).Hour <= 12) CoverTime = 0;
        else if (DateTime.Parse(StartTime).Hour >= 12 && DateTime.Parse(EndTime).Hour <= 18) CoverTime = 1;
        else if (DateTime.Parse(StartTime).Hour >= 18) CoverTime = 3;
        else if (DateTime.Parse(StartTime).Hour <= 12 && DateTime.Parse(EndTime).Hour >= 12) CoverTime = 0;
        else if (DateTime.Parse(StartTime).Hour <= 18 && DateTime.Parse(EndTime).Hour >= 18) CoverTime = 1;
        return CoverTime;
    }
    #endregion
}
